package com.organizadorestudiantil;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.CalendarView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {

	public static float init_x;
	private static ViewFlipper vf;	
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);		
		//Maneja la base de datos
		SQLiteDatabase db = this.openOrCreateDatabase("organizadordb", MODE_WORLD_WRITEABLE, null);		
		ControlDB cdb = new ControlDB(this);
		cdb.crearBD(db);
		
		vf = (ViewFlipper) findViewById(R.id.viewFlipper);
		vf.setOnTouchListener(new ListenerTouchViewFlipper(MainActivity.init_x,MainActivity.vf));
		
		cargarCursos((LinearLayout)findViewById(R.id.cursoLayout));		
	}
	
	public void cargarCursos(LinearLayout cLayout){
		SQLiteDatabase db = this.openOrCreateDatabase("organizadordb", MODE_WORLD_READABLE, null);
    	Cursor c = db.rawQuery(" SELECT * FROM Curso ",null);	
       	
    	if (c.moveToFirst()) {
    		do {
    			TextView tv = new TextView(this);
    			tv.setText(c.getString(1));
    			tv.setTextSize(25);
    			tv.setTextColor(c.getInt(2));
    			tv.setBackgroundColor(Color.WHITE);
    			cLayout.addView(tv);
    		} while(c.moveToNext());
    	}    	
    	db.close();    	
	}	
	
	public void callCalendar(View v){
		CalendarView cv = (CalendarView)findViewById(R.id.calendarMes);		
		Toast.makeText(this, "Fecha select: "+String.valueOf(cv.getDate()), 5000);				
	}
	
	public void agregarCurso(View v){
		Intent i = new Intent(this, ingresoCurso.class);
        startActivity(i);
	}	
		
	public void listarCursos(View v){
		Intent i = new Intent(this, ListadoCursos.class);
		startActivity(i);
	}
	
	public void agregarTarea(View v){
		Intent i = new Intent(this, IngresoTarea.class);
        startActivity(i);
	}
		
	public void listarActividades(View v){
		Intent i = new Intent(this, Actividades.class);
        startActivity(i);        
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}	
}
